package org.jeecg.modules.core.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;

/**
 * @ClassName
 * @Description TODO
 * @Author czd
 * @Date 2021/12/28 16:23
 * @Version 1.0
 **/
@Slf4j
public class BimStringUtil {

    public static HashMap<String, Object> strToMap(String param) {
        if (param.isEmpty()) {
            return null;
        }
        HashMap resultMap = new HashMap<>();
        try {
            resultMap = JSON.parseObject(param, HashMap.class);
        } catch (Exception ex) {
            log.error("strToMap方法解析失败：" + param);
        }
        return resultMap;
    }


    /**
     * 解析路径值
     */
    public static String parsePath(String content, String path){
        String result = content;
        String[] keyArr = path.split("\\.");
        for (String key : keyArr) {
            JSONObject parseObject = JSON.parseObject(result);
            result = parseObject.getString(key);
        }
        return result;
    }
}
